var urlCouponList = server_host + '/uweb/coupon/order/userCouponList.do'

var shopId = getParameterByName('shopId');
var cash = getParameterByName('cash');

var shopId = getParameterByName('shopId');
var shopTablePriceId = getParameterByName('shopTablePriceId');
var orderDate = getParameterByName('orderDate');
var time = getParameterByName('time');
var themeName = getParameterByName('themeName');
var tableId = getParameterByName('tableId');
var styleId = getParameterByName('styleId');

var foodIds = getParameterByName('foodIds');

var appModule = angular.module('useCoupon', []);
appModule.controller('useCouponCtrl', ['$scope', '$http', function($scope, $http) {

	// 选择红包
	$scope.showBtn = false;
	$scope.switch = function(index){
		$scope.showBtn = true;

		$scope.selectedCouponId = index;
		$scope.ticketValue = $scope.CouponInfo.list[index].ticketValue;
		$scope.userCouponId = $scope.CouponInfo.list[index].userCouponId;
		// cType带到返回的一页
		$scope.cType = $scope.CouponInfo.list[index].cType;

		console.log($scope.ticketValue);
		console.log($scope.userCouponId);
	}

	console.log(foodIds);
	// 获取红包列表
	// $scope.loadCouponList = function(){
	// 	$http.get(urlCouponList + '?shopId=' + shopId + '&cash=' + cash).success(function(data, status, headers, config) {
	// 		console.log(data);
	// 		$scope.CouponInfo = data.data;
	// 	});
	// }
	$scope.loadCouponList = function(){
		if(getParameterByName('fr')){
			urlCouponList = server_host + '/uweb/coupon/food/userCouponList.do';
		}

		$http.get(urlCouponList + '?shopId=' + shopId + '&cash=' + cash + '&foodIds=' + foodIds).success(function(data, status, headers, config) {
			console.log(data);
			$scope.CouponInfo = data.data;
		});
	}

	// 返回上一页
	$scope.ToConfirmOrder = function(){

		$scope.ticketValue = $scope.ticketValue?$scope.ticketValue:0;

		if(getParameterByName('fr'))
			location.href = 'order-food-confirm.html' + '?ticketValue=' + $scope.ticketValue +'&foodIds='+ foodIds +'&cType=' + $scope.cType + '&userCouponId=' + $scope.userCouponId + '&params=' +  getParameterByName('params');
		else
			location.href = 'confirm-order.html' + '?ticketValue=' + $scope.ticketValue + '&userCouponId=' + $scope.userCouponId + '&cType=' + $scope.cType + '&shopId=' + shopId + '&cash=' + cash + '&styleId=' + styleId + '&tableId=' + tableId + '&orderDate=' + orderDate + '&time=' + time + '&shopTablePriceId=' + shopTablePriceId + '&themeName=' + themeName;
	}

	$scope.loadCouponList();
}]);